#include <iostream>
using namespace std;

double pow1(double x, int n) {
    // Start typing your C/C++ solution below
    // DO NOT write int main() function
    if(n==0)
        return 1.0;
    if(n==1)
        return x;
    if(n==-1)
        return 1/x;
    
    double delta = x - 1.0;
    delta = delta > 0.0 ? delta : -delta;
    if(delta < 0.00000001)
        return x;

    delta = x + 1.0;
    delta = delta > 0.0 ? delta : -delta;
    if(delta < 0.00000001)
    {
        if(n%2){
            return x;
        }
        else{
            return -x;
        }
    }
        

    unsigned int absn = n > 0?  n : -n;
    double p = x;
    double acc = 1.0;
    // get bits of n
    int bits = 0;
    int tempN = absn; 
    while(tempN != 0){
        tempN >>= 1;
        ++bits;
    }
    // do 
    tempN = absn;
    for(int i=0; i<bits; ++i){
        if((tempN & 0x1) != 0){
            acc *= p;
        }
        p *= p;
        tempN >>= 1;
    }
    if(n>0)
        return acc;
    else
        return 1/acc;
}

int main(){
    cout<<pow1(2,-2)<<endl;
}